<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/dute_favicon_32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/dute_favicon_16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <link rel="manifest" href="/images/manifest.json">
  <meta name="msapplication-config" content="/images/browserconfig.xml">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="google-site-verification" content="mpI5dkydstZXl6UcDCppqktXK0bbvqdZ6LkZ3KNk4Iw">
  <meta name="baidu-site-verification" content="code-a1LksZX2Ds">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"whitestore.top","root":"/","scheme":"Gemini","version":"7.8.0","exturl":true,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="压力测试回顾第三部分">
<meta property="og:type" content="article">
<meta property="og:title" content="Jmeter压力测试回顾(三)">
<meta property="og:url" content="https://whitestore.top/2021/01/18/jmeter-test3/index.html">
<meta property="og:site_name" content="爱看书的阿东">
<meta property="og:description" content="压力测试回顾第三部分">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210109174815.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210109193233.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210109193752.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210109194054.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210109200104.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110135332.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110135654.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110165045.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110165240.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110170707.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110183037.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110191818.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110195206.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110200116.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110200938.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110201135.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110201155.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210111001343.png">
<meta property="og:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210111001434.png">
<meta property="article:published_time" content="2021-01-18T15:35:12.000Z">
<meta property="article:modified_time" content="2023-07-16T06:28:09.224Z">
<meta property="article:author" content="阿东">
<meta property="article:tag" content="压力测试回顾第三部分">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210109174815.png">

<link rel="canonical" href="https://whitestore.top/2021/01/18/jmeter-test3/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Jmeter压力测试回顾(三) | 爱看书的阿东</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="爱看书的阿东" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">爱看书的阿东</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">赐他一块白色石头，石头上写着新名</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://whitestore.top/2021/01/18/jmeter-test3/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="阿东">
      <meta itemprop="description" content="随遇而安">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="爱看书的阿东">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Jmeter压力测试回顾(三)
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-01-18 23:35:12" itemprop="dateCreated datePublished" datetime="2021-01-18T23:35:12+08:00">2021-01-18</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2023-07-16 14:28:09" itemprop="dateModified" datetime="2023-07-16T14:28:09+08:00">2023-07-16</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%B5%8B%E8%AF%95/" itemprop="url" rel="index"><span itemprop="name">测试</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/01/18/jmeter-test3/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/01/18/jmeter-test3/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>5.1k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>5 分钟</span>
            </span>
            <div class="post-description">压力测试回顾第三部分</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="回顾Jmeter压力测试（三）"><a href="#回顾Jmeter压力测试（三）" class="headerlink" title="回顾Jmeter压力测试（三）"></a>回顾Jmeter压力测试（三）</h1><h1 id="GUI实战部分"><a href="#GUI实战部分" class="headerlink" title="GUI实战部分"></a>GUI实战部分</h1><p>通过菜单了解Jmeter大致的内容之后，我们依靠实战来更深入的理解各种功能</p>
<a id="more"></a>

<h2 id="线程组的基本使用："><a href="#线程组的基本使用：" class="headerlink" title="线程组的基本使用："></a>线程组的基本使用：</h2><p>准备部分：</p>
<ol>
<li>准备一个springBoot项目，或者找一个可以访问的接口，当然最好不要访问一些外网IP，容易误认为攻击封IP</li>
<li>比如个人写了一个简单的DEMO：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@RequestMapping</span>(<span class="string">"/jmeter"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">JmeterTest</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@RequestMapping</span>(<span class="string">"/runTest1"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">testThread</span><span class="params">()</span></span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">"hello-world"</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p>1 添加-&gt;threads-&gt;线程组（控制总体并发）</p>
<p>案例：如下图所示，添加一个20个线程，循环1次的线程组，在2秒内完成</p>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210109174815.png" alt=""></p>
<ul>
<li>线程数：虚拟用户数。一个虚拟用户占用一个进程或线程</li>
<li>准备时长（Ramp-Up Period(in seconds)）：全部线程启动的时长，比如100个线程，20秒，则表示20秒内100个线程都要启动完成，每秒启动5个线程</li>
<li>循环次数：每个线程发送的次数，假如值为5，100个线程，则会发送500次请求，可以勾选永远循环    </li>
</ul>
<p>2 线程组 -&gt; 添加-&gt; Sampler(采样器) -&gt; Http请求</p>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210109193233.png" alt=""></p>
<p>一个线程组下面可以增加几个Sampler</p>
<ul>
<li>名称：采样器名称</li>
<li>注释：对这个采样器的描述</li>
<li>web服务器：<ul>
<li>默认协议是http</li>
<li>默认端口是80</li>
<li>服务器名称或IP ：请求的目标服务器名称或IP地址</li>
</ul>
</li>
<li>路径：服务器URL        </li>
<li><strong>Use multipart/from-data for HTTP POST</strong> ：当发送POST请求时，使用`Use multipart/from-data方法发送，默认不选中。</li>
</ul>
<blockquote>
<p>吐槽：感觉中间的选框太小了</p>
</blockquote>
<p>3 请求-查看测试结果</p>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210109193752.png" alt=""></p>
<p>如之前介绍菜单所说，还需要增加一个监听器，收集请求的最终结果。</p>
<p>操作如下：线程组-&gt;添加-&gt;监听器-&gt;察看结果树</p>
<p>如上图所示，最终的测试结果都是正确，两秒内开启20个线程并发访问，压力还是比较小的。</p>
<h2 id="断言的基本使用"><a href="#断言的基本使用" class="headerlink" title="断言的基本使用"></a>断言的基本使用</h2><p>上面的案例是一个最简单的线程组的使用，有点类似postMan请求接口。下面了解一下断言是如何使用的。</p>
<ol>
<li>增加断言: 线程组 -&gt; 添加 -&gt; 断言 -&gt; 响应断言</li>
</ol>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210109194054.png" alt=""></p>
<p>下面增加一个相应的断言，响应断言里面的选择内容如下：</p>
<p>测试字段：根据测试字段匹配结果，</p>
<p>中间：apply to(应用范围):<br>    <code>Main sample only:</code> 仅当前父取样器 进行断言，一般一个请求，如果发一个请求会触发多个，否则就使用<code>sub sample</code>（比较少用） </p>
<p>匹配规则：一些逻辑的匹配规则，比如包含，匹配，相等</p>
<p>这一块的组合形式比较丰富，下面简单举几个例子：</p>
<ul>
<li>响应文本：即响应的数据，比如json等文本</li>
<li>响应代码：http的响应状态码，比如200，302，404这些</li>
<li>响应信息：http响应代码对应的响应信息，例如：OK, Found</li>
<li>Response Header: 响应头</li>
</ul>
<p>模式匹配规则：</p>
<ul>
<li>包括：包含在里面就成功</li>
<li>匹配：响应内容完全匹配，不区分大小写</li>
<li>equals：完全匹配，区分大小写</li>
</ul>
<p>断言结果监听器: 线程组-&gt; 添加 -&gt; 监听器 -&gt; 断言结果</p>
<p>里面的内容是sampler采样器的名称<br>断言失败，查看结果树任务结果颜色标红(通过结果数里面双击不通过的记录，可以看到错误信息)</p>
<p>2、响应断言案例：</p>
<p>给出一个请求的信息内容：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">Thread Name:20线程2秒内容完成 1-1</span><br><span class="line">Sample Start:2021-01-09 19:57:43 CST</span><br><span class="line">Load time:1</span><br><span class="line">Connect Time:0</span><br><span class="line">Latency:1</span><br><span class="line">Size in bytes:173</span><br><span class="line">Sent bytes:134</span><br><span class="line">Headers size in bytes:162</span><br><span class="line">Body size in bytes:11</span><br><span class="line">Sample Count:1</span><br><span class="line">Error Count:0</span><br><span class="line">Data type (&quot;text&quot;|&quot;bin&quot;|&quot;&quot;):text</span><br><span class="line">Response code:200</span><br><span class="line">Response message:</span><br></pre></td></tr></table></figure>

<p>下面创建一个响应断言：</p>
<p>我们指定响应文本为：Hello-world，测试字段为响应文本，在下方输入<code>hello-world</code>用于增加断言的信息。</p>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210109200104.png" alt=""></p>
<p>在查看結果树里面就可以看到对应的信息内容了</p>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110135332.png" alt=""></p>
<p>大小断言：可以断言响应请求里面的size大小，单位为<code>Byte</code></p>
<p>断言的功能相对比较简单，这里仅仅列出了一些简单案例</p>
<h2 id="聚合报告分析"><a href="#聚合报告分析" class="headerlink" title="聚合报告分析"></a>聚合报告分析</h2><p>操作方式：新增聚合报告：线程组-&gt;添加-&gt;监听器-&gt;聚合报告（Aggregate Report）</p>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110135654.png" alt=""></p>
<p>介绍一下英文版的内容对应列的含义</p>
<ul>
<li>lable: sampler的名称</li>
<li>Samples: 一共发出去多少请求,例如10个用户，循环10次，则是 100</li>
<li>Average: 平均响应时间</li>
<li>Median: 中位数，也就是 50％ 用户的响应时间</li>
<li>90% Line : 90％ 用户的响应不会超过该时间 （90% of the samples took no more than this time. The remaining samples at least as long as this）</li>
<li>95% Line : 95％ 用户的响应不会超过该时间</li>
<li>99% Line : 99％ 用户的响应不会超过该时间</li>
<li>min : 最小响应时间</li>
<li>max : 最大响应时间</li>
<li>Error%：错误的请求的数量/请求的总数</li>
<li>**Throughput： 吞吐量——默认情况下表示每秒完成的请求数（Request per Second) 可类比为qps<pre><code>KB/Sec: 每秒接收数据量**</code></pre></li>
</ul>
<p>新增聚合报告之后，就可以在聚合报告里面看到对应的结果，注意聚合报告的内容都是累加的</p>
<h2 id="用户自定义变量"><a href="#用户自定义变量" class="headerlink" title="用户自定义变量"></a>用户自定义变量</h2><p>如果想要设置一些常用的变量配置放到当前的线程组里面，可以使用如下的方式</p>
<p>作用：</p>
<p>很多变量在全局中都有使用，或者测试数据更改，可以在一处定义，四处使用(比如服务器地址)</p>
<p>操作方法：</p>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110165045.png" alt=""></p>
<p>线程组-&gt;add -&gt; Config Element(配置原件)-&gt; User Definde Variable（用户定义的变量）</p>
<p>如上图配置完成之后，引用方式如下：${XXX}，在接口中变量中使用，如下所示：</p>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110165240.png" alt=""></p>
<h2 id="CSV可变参数"><a href="#CSV可变参数" class="headerlink" title="CSV可变参数"></a>CSV可变参数</h2><p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110170707.png" alt=""></p>
<p>1、线程组-&gt;add -&gt; Config Element(配置原件)-&gt; CSV data set config (CSV数据文件设置)</p>
<p>我们在电脑的任意位置配置txt文件，配置方式如下：</p>
<p>新建一个txt文件，同时注意使用utf-8的编码进行保存。</p>
<p>2、在读取的配置文件里面，同时使用多个自定义参数</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">username,password,gender</span><br><span class="line">zhangsan,test001,1</span><br><span class="line">lisi,test002,2</span><br><span class="line">wanglaowu,test003,2</span><br><span class="line">laoliu,test004,1</span><br></pre></td></tr></table></figure>

<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110183037.png" alt=""></p>
<p>接着我们可以唉csv可变参数里面按照要求进行配置：</p>
<ul>
<li>文件名：csv文件的名字</li>
<li>文件编码：当前文件的编码格式</li>
<li>变量名称：对应标头，用逗号分隔</li>
<li>忽略首行：蛀牙要设置变量名称的时候才会生效</li>
<li>分隔符：默认分隔符为逗号</li>
<li>是否带有引号：(未验证)</li>
<li>遇到文件结束符之后再次循环：意味着是否需要重复的读取文件的内容</li>
<li>遇到文件结束符终止线程：只读一遍文件</li>
<li>线程共享模式：默认应用当前<strong>所有</strong>线程组</li>
</ul>
<h2 id="JDBC-request压测Mysql"><a href="#JDBC-request压测Mysql" class="headerlink" title="JDBC request压测Mysql"></a>JDBC request压测Mysql</h2><h3 id="简单应用入门："><a href="#简单应用入门：" class="headerlink" title="简单应用入门："></a>简单应用入门：</h3><p>在正式进行使用之前，需要随意建立一个数据库或表。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">CREATE TABLE &#96;admin&#96;  (</span><br><span class="line">  &#96;id&#96; int(11) NOT NULL AUTO_INCREMENT,</span><br><span class="line">  &#96;account&#96; varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,</span><br><span class="line">  &#96;password&#96; varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,</span><br><span class="line">  &#96;power&#96; int(11) NULL DEFAULT NULL,</span><br><span class="line">  PRIMARY KEY (&#96;id&#96;) USING BTREE</span><br><span class="line">) ENGINE &#x3D; InnoDB AUTO_INCREMENT &#x3D; 52 CHARACTER SET &#x3D; utf8 COLLATE &#x3D; utf8_general_ci ROW_FORMAT &#x3D; Dynamic;</span><br></pre></td></tr></table></figure>

<p>使用Jdbc进行压力测试，需要依赖jar包实现，不同的版本jar包压测的结果可能会有出入</p>
<ol>
<li>Thread Group -&gt; add -&gt; sampler -&gt; jdbc request</li>
</ol>
<p>这时候进行请求是肯定无效的，我们只是建立的一个采样器：</p>
<ol start="2">
<li>jar包添加  mysql-connector-java-5.1.30.jar </li>
</ol>
<p>我们需要在配置元件里面，对于个人的JDBC进行配置</p>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110191818.png" alt=""></p>
<ol start="3">
<li>JDBC connection Configuration 配置</li>
</ol>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110195206.png" alt=""></p>
<p>Max number of connections：最大连接数</p>
<p>Time-between-eviction-runs-millis：指定空闲连接检查、废弃连接清理、空闲连接池大小调整之间的操作时间间隔</p>
<p>variable name for created pool：创建池的变量名</p>
<p>Auto commit：是否自动提交</p>
<p>Transaction Isolation：事务隔离级别（注意Mysql默认级别为读已提交）</p>
<p>Preinit Pool：预初始化池</p>
<p>Test while idle：空闲线程测试</p>
<p>Soft Min Evictable Idle Time：软最小可收回空闲时间</p>
<p>Validation Query：验证查询</p>
<p>最下面的部分为JDBC连接，最后一项是连接的参数配置。</p>
<p>DataBase URL : 数据库连接地址 jdbc:mysql://127.0.0.1:3306/blog<br>JDBC Driver Class : 数据库驱动，选择对应的mysql<br>username：数据库用户名<br>password：数据库密码</p>
<ol start="4">
<li>将<code>mysql-connector-java.xxx.jar</code>拷贝到jmeter的classpath目录：（核心步骤）</li>
</ol>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110200116.png" alt=""></p>
<ol start="5">
<li>注意一下配置一定要准确，否则请求会抛出错误，请求失败也不要慌，多看看返回的提示信息，个人在实验的过程中也不是一次成功的：</li>
</ol>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110200938.png" alt=""></p>
<ol start="6">
<li>发起测试请求：</li>
</ol>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110201135.png" alt=""></p>
<p>下面的数据为随便录入的一些数据，可以参考自己的测试结果</p>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210110201155.png" alt=""></p>
<h3 id="查询参数："><a href="#查询参数：" class="headerlink" title="查询参数："></a>查询参数：</h3><p>GUI在查询参数这一部分不是十分好，下面说下如果需要使用？这一类形式替换要如何处理</p>
<p>如果使用占位符，在jmeter的GUI界面，需要使用括号进行替换，（1）代表取第一个参数。</p>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210111001343.png" alt=""></p>
<p><img src="https://gitee.com/lazyTimes/imageReposity/raw/master/img/20210111001434.png" alt=""></p>
<p>下面为填入的内容介绍：</p>
<p><strong>Variable name：</strong>这里写入数据库连接池的名字（和JDBC Connection Configuration名字保持一致 ）<br><strong>Query：</strong>里面填入查询数据库数据的SQL语句（填写的SQL语句末尾不要加“；”）<br><strong>parameter valus：</strong>数据的参数值<br><strong>parameter types：</strong>数据的参数类型<br><strong>cariable names：</strong>保存SQL语句返回结果的变量名<br><strong>result cariable name：</strong>创建一个对象变量，保存所有返回结果<br><strong>query timeout：</strong>查询超时时间<br><strong>handle result set：</strong>定义如何处理由callable statements语句返回的结果</p>
<h2 id="分布式压测"><a href="#分布式压测" class="headerlink" title="分布式压测"></a>分布式压测</h2><p>官网教程： <span class="exturl" data-url="aHR0cDovL2ptZXRlci5hcGFjaGUub3JnL3VzZXJtYW51YWwvam1ldGVyX2Rpc3RyaWJ1dGVkX3Rlc3Rpbmdfc3RlcF9ieV9zdGVwLmh0bWw=" title="http://jmeter.apache.org/usermanual/jmeter_distributed_testing_step_by_step.html">http://jmeter.apache.org/usermanual/jmeter_distributed_testing_step_by_step.html<i class="fa fa-external-link"></i></span></p>
<ul>
<li>普通压测：单台机可以对目标机器产生的压力比较小，受限因素包括CPU，网络，IO等</li>
<li>分布式压测：利用多台机器向目标机器产生压力，模拟几万用户并发访问</li>
</ul>
<p>由于分布式的压测一般对于服务器的配置要求较高，个人一个弱鸡服务器就不献丑了，这里推荐一篇分布式压测文章推荐：</p>
<p>简书文章：<span class="exturl" data-url="aHR0cHM6Ly93d3cuamlhbnNodS5jb20vcC81YzA0NzkyYzMxYjY=" title="https://www.jianshu.com/p/5c04792c31b6">https://www.jianshu.com/p/5c04792c31b6<i class="fa fa-external-link"></i></span></p>
<p>官方文档：<span class="exturl" data-url="aHR0cHM6Ly9qbWV0ZXIuYXBhY2hlLm9yZy91c2VybWFudWFsL2ptZXRlcl9kaXN0cmlidXRlZF90ZXN0aW5nX3N0ZXBfYnlfc3RlcC5odG1s" title="https://jmeter.apache.org/usermanual/jmeter_distributed_testing_step_by_step.html">https://jmeter.apache.org/usermanual/jmeter_distributed_testing_step_by_step.html<i class="fa fa-external-link"></i></span></p>
<p>Jmeter分布式压测原理(了解)</p>
<p>1、总控机器的节点master，其他产生压力的机器叫“肉鸡” server</p>
<p>2、master会把压测脚本发送到 server上面</p>
<p>3、执行的时候，server上只需要把jmeter-server打开就可以了，不用启动jmeter</p>
<p>4、结束后，server会把压测数据回传给master,然后master汇总输出报告</p>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.css">
    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>lazytime
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://whitestore.top/2021/01/18/jmeter-test3/" title="Jmeter压力测试回顾(三)">https://whitestore.top/2021/01/18/jmeter-test3/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLzQuMC96aC1DTg=="><i class="fa fa-fw fa-creative-commons"></i>BY-NC</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E6%B5%8B%E8%AF%95/" rel="tag"># 测试</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/01/18/jmeter-test1/" rel="prev" title="Jmeter压力测试回顾(二)">
      <i class="fa fa-chevron-left"></i> Jmeter压力测试回顾(二)
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/01/18/jmeter-test4/" rel="next" title="Jmeter压力测试回顾(四)">
      Jmeter压力测试回顾(四) <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#回顾Jmeter压力测试（三）"><span class="nav-number">1.</span> <span class="nav-text">回顾Jmeter压力测试（三）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#GUI实战部分"><span class="nav-number">2.</span> <span class="nav-text">GUI实战部分</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#线程组的基本使用："><span class="nav-number">2.1.</span> <span class="nav-text">线程组的基本使用：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#断言的基本使用"><span class="nav-number">2.2.</span> <span class="nav-text">断言的基本使用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#聚合报告分析"><span class="nav-number">2.3.</span> <span class="nav-text">聚合报告分析</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#用户自定义变量"><span class="nav-number">2.4.</span> <span class="nav-text">用户自定义变量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#CSV可变参数"><span class="nav-number">2.5.</span> <span class="nav-text">CSV可变参数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JDBC-request压测Mysql"><span class="nav-number">2.6.</span> <span class="nav-text">JDBC request压测Mysql</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#简单应用入门："><span class="nav-number">2.6.1.</span> <span class="nav-text">简单应用入门：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查询参数："><span class="nav-number">2.6.2.</span> <span class="nav-text">查询参数：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#分布式压测"><span class="nav-number">2.7.</span> <span class="nav-text">分布式压测</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">阿东</p>
  <div class="site-description" itemprop="description">随遇而安</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">239</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">36</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">37</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;lazyTimes"><i class="fa fa-fw fa-github"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOjEwOTc0ODM1MDhAcXEuY29t" title="E-Mail → mailto:1097483508@qq.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly93d3cuNTJwb2ppZS5jbi9ob21lLnBocD9tb2Q9c3BhY2UmdWlkPTE0OTc3MTgmZG89dGhyZWFkJnZpZXc9bWUmZnJvbT1zcGFjZQ==" title="https:&#x2F;&#x2F;www.52pojie.cn&#x2F;home.php?mod&#x3D;space&amp;uid&#x3D;1497718&amp;do&#x3D;thread&amp;view&#x3D;me&amp;from&#x3D;space">吾爱破解</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9qdWVqaW4uaW0vdXNlci8yOTk5MTIzNDUyNjI2MzY2" title="https:&#x2F;&#x2F;juejin.im&#x2F;user&#x2F;2999123452626366">掘金</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9zZWdtZW50ZmF1bHQuY29tL3UvbGF6eXRpbWVz" title="https:&#x2F;&#x2F;segmentfault.com&#x2F;u&#x2F;lazytimes">思否</span>
        </li>
    </ul>
  </div>

      </div>

      <div class="wechat_OA">
        <span>欢迎关注我的公众号</span>
        <br>
          <!-- 这里添加你的二维码图片 -->
        <img src ="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/wechat_channel.jpg">
      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">阿东</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">2m</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">29:50</span>
</div>
  <div class="powered-by">由 <span class="exturl theme-link" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> & <span class="exturl theme-link" data-url="aHR0cHM6Ly90aGVtZS1uZXh0Lm9yZw==">NexT.Gemini</span> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : true,
      appId      : 'qMUpEEvBgXaMDD1b0ftgi9xr-gzGzoHsz',
      appKey     : 'UCdfT4Rfih6MO6y8DI4fstf6',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
